package com.quarkus.resource;

import com.quarkus.entity.des.UserDes;
import com.quarkus.repository.UserDesRepository;
import io.quarkus.hibernate.orm.PersistenceUnit;

import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.print.attribute.standard.Media;
import javax.transaction.Transactional;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

/**
 * @Author: TongRui乀
 * @Date: 2021/3/28 15:12
 * @description：
 */
@Path("des")
public class UserDesResource {

    @Inject
    UserDesRepository userDesRepository;


    @GET
    @Path("{id}")
    @Produces(MediaType.APPLICATION_JSON)
    public UserDes get(@PathParam("id") Long id){
        return userDesRepository.findById(id);
    }

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @Transactional
    public UserDes save(UserDes userDes){
        userDesRepository.persist(userDes);
        return userDes;
    }

    @DELETE
    @Path("{id}")
    @Transactional
    public boolean delete(@PathParam("id") Long id){
        return userDesRepository.deleteById(id);
    }

    @PUT
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @Transactional
    public UserDes updateById(UserDes userDes){
        UserDes des = userDesRepository.findById(userDes.getId().longValue());
        des.setDes(userDes.getDes());
        des.setName(userDes.getName());
        return des;
    }
}
